﻿/*
   Open Intel 
   Copyright © 2011 – ISC. All Rights Reserved.
*/


using System;
using Caliburn.Micro;
using OI.Framework;

namespace OI.Async
{
    public class SharingServiceWrite : SharingServiceBase
    {
        public Guid ID { get; private set; }
        public string State { get; private set; }

        public SharingServiceWrite(Guid id, string state)
        {
            ID = id;
            State = state;
            Client.WriteStateCompleted += WriteStateCompleted;
        }


        void WriteStateCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                IoC.Get<IShell>().HandleException(e.Error, "Error saving share state");
            }

            Completed(this, new ResultCompletionEventArgs { Error = e.Error });
        }


        public override void Execute(ActionExecutionContext context)
        {
            Client.WriteStateAsync(ID, State);
        }

        public override event EventHandler<ResultCompletionEventArgs> Completed;
    }
}
